package com.company.creational.singleton_pattern.lazy;

/**
 * @ClassName LazySingleton2
 * @Author tiezheng.han
 * @Date 2020/8/28 9:42
 **/
public class LazySingleton1 {

    private static LazySingleton1 instance = null;

    private LazySingleton1(){}

    /**
     * 使用synchronize关键字对方法加锁，确保任意时刻只有一个线程可执行该方法
     */
    synchronized public static LazySingleton1 getInstance(){
        if (instance == null){
            instance = new LazySingleton1();
        }
        return instance;
    }

}
